

<body>

    <div class="hd">
        <div class="warp">
            <ul class="btn-list">
                <li class="item">

                    <a href="<?php echo $base_url?>home/order/shoppingcar" class="shop-car bg">
                        <!--<div class="num">1</div>-->
                        <i class="icon iconfont icon-icon"></i>
                    </a>
                </li>
                <li  class="item">
                     <!--<a href="./register.html">
                        <i class="iconfont icon-wode"></i>请登录
                    </a>-->
                    <?php if(isset($user)){?>
                    <span href="#" class="bg">
                        <i class="icon iconfont icon-wode"></i><?php echo $user->mobile;?>
                    </span>
                    
                    <ul class="child-item">
                            <li><a href="<?php echo $base_url?>home/order/userorders">我的订单</a></li>
                            <li><a href="<?php echo $base_url?>home/address">收货地址</a></li>
                            <li><a href="<?php echo $base_url;?><?php if(!empty($cardid)){echo 'home/card/cardlist';}else{echo 'home/card/addcard';}?>">绑定银行卡</a></li>
                            <li><a href="<?php echo $base_url?>home/account/logout">退出商城</a></li>
                    </ul>
                    <?php }else{?>
                    <a href="<?php echo $base_url?>home/account/login?back_url=<?php echo urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?>">
                        <i class="iconfont icon-wode"></i>请登录
                    </a>
                    <?php }?>
                </li>
            </ul>
            <a href="<?php echo $base_url?>home/goods/index">
            <img src="<?php echo $base_url?>static/dist/images/logo.png" alt="" class="logo-img">
             <span class="span_txt">商城首页</span>
            </a>
        </div>
    </div>

  <div class="order_details2">
        <div class="warp">
            <p class="tit">订单详情</p>
            <div class="order_status">
                <p class="txt">已拍下，请在<span class="time"> 分</span>内付款 </p>
                <p class="txt">若未及时付款，系统将自动取消订单</p>
                <!-- <a href="#1123" class="pay_btn">立即支付</a> -->
            </div>
        </div>
    </div>
     <div class="pay-bar">
        <div class="warp">
            <p class="tit">
                支付方式
            </p>
            <ul class="pay-type">
                <li class="pay-item active" data-paytype='3'>
                    <i class="iconfont icon-zhifu"></i>
                    <span>支付宝</span>
                </li>
                <li class="pay-item" data-paytype='1'>
                    <i class="iconfont icon-ananzuiconv267"></i>
                    <span>微信</span>
                </li>

                <!-- <li class="pay-item">
                    <img src="<?php echo $base_url?>static/dist/images/qdd-ico.jpg" alt="">
                </li> -->
            </ul>
        </div>
    </div>
    <div class="pd-20"></div>

    <div class="order_details">
        <div class="warp">
            <!--<p class="tit">订单详情</p>
            <div class="order_status">
                <p class="txt">已拍下，请在<span class="time">30 分钟</span>内付款 </p>
                <p class="txt">若未及时付款，系统将自动取消订单</p>
                <a href="#1123" class="pay_btn">立即支付</a>
            </div>-->
            <!--<p class="pd-20"></p>-->
            <div class="order_item">
                <div class="order_tit">
                    <p class="r"><span class="dfk">待付款</span></p>
                    <p class="msg">
                       <span class="order_num">订单号：<?php echo $data['order_id']; ?></span> <span class="time"><?php echo date('Y-m-d H:i:s', $data['create_time']); ?></span>
                    </p>
                </div>
                <div class="order_warp type2">
                    <div class="l_order_box">
                        <ul>
                            <?php foreach($data['detail'] as $key => $value): ?>
                            <li class="order_child_item">
                                <div class="l_img">
                                    <img src="<?php echo $value['img_path']; ?>" alt="">
                                </div>
                                <div class="l_msg">
                                    <p class="name"><?php echo $value['goods_name']; ?></p>
                                    <p class="msg"><?php echo $value['other_name']; ?></p>
                                    <p class="qy"><i class="iconfont icon-lingchengben"></i><?php echo $value['activity_desc']; ?></p>
                                </div>
                                <div class="l_sku">
                                    <!-- <p class="sku_txt">颜色分类：黄色；</p> -->
                                </div>

                                
                                <div class="l_num">
                                    <p class="num_txt">数量：×<?php echo $value['amount']; ?></p>
                                </div>
								<div class="l_price">
                                    <p class="price_txt">单价:¥<?php echo $value['price']; ?></p>
                                </div>
                            </li>
                            <?php endforeach; ?>
                        </ul>
                    </div>
                </div>
                <div class="order_msg type2">
                    <p class="msg"> <span class="msg_tit">收货地址：</span><?php echo $data['username']; ?>；  <?php echo $data['mobile']; ?>；  <?php echo $data['address']; ?></p>
                    <p class="remarks-txt">
                        <span>买家备注：</span>
						<span class="txt_bz">
							<?php echo $data['leave']; ?>
						</span>
                        <!--s<input type="text" placeholder="" value="<?php echo $data['leave']; ?>" readonly>-->
                    </p>

                </div>
            </div>
        </div>
    </div>
    <div class="pd-20"></div>

    <div class="remarks-bar">
        <div class="warp">
            <!--<div class="remarks-txt">
                <span>买家备注：</span>
                <input type="text" placeholder="选填，对本次交易订单的说明">
            </div>-->
            <div class="sub-box">
                <p class="type"><span>支付方式：</span> <span class="val pay-type" id="paytype">支付宝</span> </p>
                <p class="type"><span>配送方式：</span> <span class="val ">快递免邮</span> </p>
                <p class="type"><span>应付：</span> <span class="val price"> <span>¥</span><?php echo $data['price']; ?></span>
                </p>
                <a href="javascript:void(0);" class="sub-btn" data-enable="1">支付</a>
            </div>
        </div>
    </div>
    <div class="pd-200"></div>
    <?php $this->load->view('home/pc/comm'); ?>
    <div class="pay_modal">
        <div class="bg">
            <p class="tit">收款方：深圳市养悦源健康产业有限公司</p>
            <a class="col_btn">
                <i class="iconfont icon-icon1"></i>
            </a>
             <div class="cont">
                 <p class="sm-msg">扫一扫付款（元)</p>
                 <p class="price"><?php echo $price; ?></p>
                 <div class="qrCode-box">
                     <img src="" alt="">
                 </div>
                 <p class="ft_msg">打开手机<span id='modal_paytype'>支付宝</span></p>
                 <p class="ft_msg">扫一扫继续付款</p>
             </div>
        </div>
    </div>
    <input id='order_id' type="hidden" value="<?php echo $data['order_id']; ?>">
    <input id='left_time' type="hidden" value="<?php echo $data['left_time']; ?>">
    <!--<input id='left_time' type="hidden" value="1">-->
	
    

    <script src="<?php echo $base_url?>static/dist/js/lib/jquery.min.js"></script>
    <!--<script src="<?php echo $base_url?>static/dist/js/lib/store.legacy.min.js"></script>-->


    <script>
        $(function(){
            //初始化购物车
            // var cartData = store.get('cartData') || [];
			var cartData = getCookie('cartData') || [];
            if(cartData.length != 0){           
				fillCart();             
            }
            //计算购物车商品总数量
            function fillCart() {
                var htmlStr = '';
                var sum = 0, num = 0;
                for (var i = 0; i < cartData.length; i++) {
                    num = parseInt(cartData[i].quantity) || 0;
                    if (num) {
                        sum += num;
                    }
                }
                if (sum >= 100) {
                    sum = '99+'
                }
				if(sum == 0){
					 $('.shop-car').find('.num').addClass('none');
					 
					 return;
				}
                htmlStr = '<div class="num">' + sum + '</div>';
                $numEl = $('.shop-car .num');
                if ($numEl.length == 0) {
                    $('.shop-car').append(htmlStr)
                } else {
                    $numEl.html(sum)
                }
            }

            //切换支付方式
            $('.pay-item').on('click', function(){
                $('.pay-item').removeClass('active');
                $(this).addClass('active');
                $('#paytype').html($(this).find('span').html());
                $('#modal_paytype').html($(this).find('span').html());
            });

            //点击提交订单
            $('.sub-btn').on('click', function(){
                var order_id = $('#order_id').val();
                payType = $('.pay-item.active').data('paytype');
                $.post("<?php echo $base_url; ?>home/order/repay", 
                        { order_id:order_id},  
                       function(data){  
                         if(data.errcode != 0)
                         {
                            alert(data.errmsg);
                            if(data.errcode == 4)
                            {
                                //订单已支付
                                location.reload();
                            }
                         } 
                         else
                         {  
                            //支付宝支付
                            if(payType == 3){
                                $.post("<?php echo $base_url; ?>ajax/payment/zhifbscpay",{order_id:order_id},function(result){
                                    // console.log(result);
                                    $('.mask-box').removeClass('none');
                                    $('.pay_modal').addClass('active');
                                    $('.pay_modal .qrCode-box img').attr('src', result.code_img_url);
                                },"json");
                            }

                            //微信支付
                            if(payType == 1){
                                $.post("<?php echo $base_url; ?>ajax/payment/wxinpay",{order_id:order_id},function(result){
                                    // console.log(result);
                                    $('.mask-box').removeClass('none');
                                    $('.pay_modal').addClass('active');
                                    $('.pay_modal .qrCode-box img').attr('src', result.code_img_url);
                                },"json");
                            }
							startPayTimer();
                         }
                       }, 
                        "json"); 
            });
			var $timeSpan = $('.order_status').find('.txt .time')
			function renderTimeTop(minute,second){				
				var secondStr = second?second+'秒':'';
				var minuteStr = minute?minute+'分':'';
				
				$timeSpan.text(minuteStr + secondStr);
			}
			//30倒计时
			var left_time_y = parseInt($("#left_time").val()) || 0;
			var left_time = left_time_y;
			var timer = null;
			function loopTime(){
				if(left_time_y<0){
					return;
				}			
				timer = setTimeout(function() {
					left_time--;
					if(left_time<=0){
						location.reload();
						clearTimeout(timer);
					}
					// renderTimeTop(parseInt(left_time/60));
					var currentTime = formatDataObj(left_time);					
					renderTimeTop(currentTime.minute,currentTime.second);
					loopTime();					
				}, 1000);
			}
			loopTime();
			// var tiemStart = parseInt(left_time/60) || 0	

			var currentTime = formatDataObj(left_time)
			renderTimeTop(currentTime.minute,currentTime.second);

			function formatDataObj(second){
				var minute = parseInt(second/60)				
				var second = parseInt(second%60)
				return {
					minute:minute,
					second:second
				}
			}

			// -------------------------------------
			var PayTimer = null, successVal = false;
			var order_id = $('#order_id').val();			
			function startPayTimer(){
				function loopPayTimerFn(){
					PayTimer = setTimeout(function() {
						getStatus(order_id);
						if(!successVal){
							loopPayTimerFn();
						}						
					}, 2000);
				}	
				loopPayTimerFn();
			}
			function getStatus(orderid){				
				$.ajax({
					url:"/ajax/Order/CheckOrderTimeOut",
					data:{"order_id":orderid},
					type:"POST",
					success:function(data){						
						data = JSON.parse(data);
						if(data.errcode == 0){
							successVal =true;	
							location.href = '/home/order/orderinfo?orderid='+orderid;
						}else if(data.errcode == 1){
							successVal =false;
						}
					},
					error:function(err){
						console.log('Ajax Error');
					}					
				})
			}


			$('.col_btn').on('click', function () {
				$('.mask-box').addClass('none');
				$(this).parents('.add_address').removeClass('active');
				$(this).parents('.pay_modal').removeClass('active'); 
				clearTimeout(PayTimer)
			})

			function getCookie(cname) {
				var name = cname + "=";
				var ca = document.cookie.split(';');
				for(var i=0; i<ca.length; i++) {
					var c = ca[i];
					while (c.charAt(0)==' ') c = c.substring(1);
					if (c.indexOf(name) != -1){
						return JSON.parse(c.substring(name.length, c.length));
					} 
				}
				return "";
			}
        });

    </script>
</body>

</html>
